package com.qianya.system.face.web.patient.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianya.model.common.CommonResult;
import com.qianya.model.common.ResultCode;
import com.qianya.model.pojo.patient.qo.PatientHisPrescriptionQO;
import com.qianya.model.pojo.patient.vo.PatientHisPrescriptionDetailsVO;
import com.qianya.model.pojo.patient.vo.PatientHisPrescriptionVO;
import com.qianya.system.face.web.patient.model.PatientFileInfo;
import com.qianya.system.face.web.patient.model.PatientHisPrescription;
import com.qianya.system.face.web.patient.service.IPatientHisPrescriptionService;
import com.qianya.system.face.web.patient.service.IPatientStatisticsService;
import com.qianya.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping("/patient/patient-statistics")
@Api(value = "PatientStatisticsController", tags = "统计报表")
@Slf4j
@Validated
public class PatientStatisticsController {
    @Autowired
    private IPatientStatisticsService statisticsService;
    @ApiOperation("患者统计")
    @GetMapping("/eatStatistics")
    public CommonResult eatStatistics( @ApiParam(value = "时间可为空 格式（yyyy-MM）",required = false)
                                           @RequestParam(defaultValue = "",name = "time")String time){
        if (!"".equals(time) && !DateUtils.valiDateTimeWithLongFormat1(time)){
            return CommonResult.error(ResultCode.ERROR,"日期格式不对");
        }
        StringBuilder stringBuilder =new StringBuilder(time);

        if (!"".equals(time)){
             stringBuilder.append("-01");
        }
        return statisticsService.eatStatistics(stringBuilder.toString());
    }
    @ApiOperation("各种统计")
    @GetMapping("/nursePharmacyStatistics")
    public CommonResult nursePharmacyStatistics( @ApiParam(value = "时间可为空 格式（yyyy-MM）",required = false)
                                                @RequestParam(defaultValue = "",name = "time")String time,
                                                @ApiParam(value = "查询条件（如科室id，院区id，病区id，护士id）",required = false)
                                                @RequestParam(defaultValue = "",name = "userId")String userId,
                                                    @ApiParam(value = "统计类型(1病区发药2科室发药3院区发药4护士发药)",required = true)
                                                     @RequestParam(defaultValue = "0",name = "type")Integer type){
        if (!"".equals(time) && !DateUtils.valiDateTimeWithLongFormat1(time)){
            return CommonResult.error(ResultCode.ERROR,"日期格式不对");
        }
        StringBuilder stringBuilder =new StringBuilder(time);

        if (!"".equals(time)){
           stringBuilder.append("-01");
        }
        if(type==0){
            return CommonResult.error(ResultCode.ERROR,"统计类型不能为空");
        }else if (type>4){
            return CommonResult.error(ResultCode.ERROR,"不是合法的统计类型");
        }
        if ("".equals(userId)){
            switch (type){
                case 0: return CommonResult.error(ResultCode.ERROR,"统计类型不能为空");
                case 1: return CommonResult.error(ResultCode.ERROR,"病区id不能为空");
                case 2: return CommonResult.error(ResultCode.ERROR,"科室id不能为空");
                case 3: return CommonResult.error(ResultCode.ERROR,"院区id不能为空");
                case 4: return CommonResult.error(ResultCode.ERROR,"护士id不能为空");
                default:break;
            }
        }
        return statisticsService.nursePharmacyStatistics(stringBuilder.toString(),userId,type);
    }


}
